package com.itheima.treesetdemo;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class MyTreeSet4 {
    public static void main(String[] args) {
        Set<Teacher> set = new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int result = o1.getAge() - o2.getAge();
                result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        });
        set.add(new Teacher("zhangsan",23));
        set.add(new Teacher("lisi",23));
        set.add(new Teacher("wangwu",26));
        set.add(new Teacher("zhaoliu",28));
        System.out.println(set);
    }
}
